package com.microstream.lift.server;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;

import com.microstream.dao.MsUser;
import com.microstream.lift.client.GreetingService;
import com.microstream.lift.guestbook.PMF;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
		GreetingService {

	//public String greetServer(String input) {
	public 	ArrayList greetServer(String input) {
		//String serverInfo = getServletContext().getServerInfo();
		//String userAgent = getThreadLocalRequest().getHeader("User-Agent");
		ArrayList usersList = new ArrayList();  
		
		try {
			
			PersistenceManager pm = PMF.get().getPersistenceManager();			
		    String query = "select from " + MsUser.class.getName();
		    List<MsUser> users = (List<MsUser>) pm.newQuery(query).execute();
		    for(int i=0;i<users.size();i++) {
		    	usersList.add(users.get(i).getUserName()); 		    	
		    }
		    return usersList; 
		}
		catch(Exception exp) {
			return null; 
		}
						
	}
}
